package com.ruoyi.cnInnovation_compet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cnInnovation_compet.domain.CnInnovationCompet;
import com.ruoyi.cnInnovation_compet.service.ICnInnovationCompetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 创新大赛Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/cnInnovation_compet/cnInnovation_compet")
public class CnInnovationCompetController extends BaseController
{
    @Autowired
    private ICnInnovationCompetService cnInnovationCompetService;

    /**
     * 查询创新大赛列表
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CnInnovationCompet cnInnovationCompet)
    {
        startPage();
        List<CnInnovationCompet> list = cnInnovationCompetService.selectCnInnovationCompetList(cnInnovationCompet);
        return getDataTable(list);
    }

    /**
     * 导出创新大赛列表
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:export')")
    @Log(title = "创新大赛", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CnInnovationCompet cnInnovationCompet)
    {
        List<CnInnovationCompet> list = cnInnovationCompetService.selectCnInnovationCompetList(cnInnovationCompet);
        ExcelUtil<CnInnovationCompet> util = new ExcelUtil<CnInnovationCompet>(CnInnovationCompet.class);
        util.exportExcel(response, list, "创新大赛数据");
    }

    /**
     * 获取创新大赛详细信息
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:query')")
    @GetMapping(value = "/{cicId}")
    public AjaxResult getInfo(@PathVariable("cicId") Long cicId)
    {
        return success(cnInnovationCompetService.selectCnInnovationCompetByCicId(cicId));
    }

    /**
     * 新增创新大赛
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:add')")
    @Log(title = "创新大赛", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CnInnovationCompet cnInnovationCompet)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        cnInnovationCompet.setDeptId(105L);
        cnInnovationCompet.setUserId(user.getUserId());
        return toAjax(cnInnovationCompetService.insertCnInnovationCompet(cnInnovationCompet));
    }

    /**
     * 修改创新大赛
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:edit')")
    @Log(title = "创新大赛", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CnInnovationCompet cnInnovationCompet)
    {
        return toAjax(cnInnovationCompetService.updateCnInnovationCompet(cnInnovationCompet));
    }

    /**
     * 删除创新大赛
     */
    @PreAuthorize("@ss.hasPermi('cnInnovation_compet:cnInnovation_compet:remove')")
    @Log(title = "创新大赛", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cicIds}")
    public AjaxResult remove(@PathVariable Long[] cicIds)
    {
        return toAjax(cnInnovationCompetService.deleteCnInnovationCompetByCicIds(cicIds));
    }
}
